package com.agency.entity;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.agency.dao.AuthenticationDao;

@ManagedBean(name="authentication")
@SessionScoped
public class Authentication {

	private Integer idAuthentication;
	private String username;
	private String password;
	private String msg, selectedusername;

	public Authentication(Integer idAuthentication, String username,
			String password, String msg, String selectedusername) {
		super();
		this.idAuthentication = idAuthentication;
		this.username = username;
		this.password = password;
		this.msg = msg;
		this.selectedusername = selectedusername;
	}
	public Integer getIdAuthentication() {
		return idAuthentication;
	}
	public void setIdAuthentication(Integer idAuthentication) {
		this.idAuthentication = idAuthentication;
	}
	public String getUAuthenticationname() {
		return username;
	}
	public void setUAuthenticationname(String uAuthenticationname) {
		this.username = uAuthenticationname;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public String getSelectedAuthenticationnamename() {
		return selectedusername;
	}
	public void setSelectedAuthenticationnamename(String selectedAuthenticationnamename) {
		this.selectedusername = selectedAuthenticationnamename;
	}
	public void saveAuthentication() {
		AuthenticationDao dao = new AuthenticationDao();
		dao.addAuthentication(this);
		this.msg = "Member Info Saved Successfull!";
		clearAll();
	}
	public void updateAuthentication() {
		AuthenticationDao dao = new AuthenticationDao();
		dao.updateAuthentication(this);
		this.msg = "Member Info Update Successfull!";
		clearAll();
	}
	public void deleteAuthentication() {
		AuthenticationDao dao = new AuthenticationDao();
		dao.deleteAuthentication(idAuthentication);
		this.msg = "Member Info Delete Successfull!";
		clearAll();
	}

	public List<Authentication> getAllAuthentications() {
		List<Authentication> Authentications = new ArrayList<Authentication>();
		AuthenticationDao dao = new AuthenticationDao();
		Authentications = dao.getAllAuthentications();
		return Authentications;
	}

	public void fullInfo() {
		AuthenticationDao dao = new AuthenticationDao();
		
		List<Authentication> lc = dao.getAuthenticationById(selectedusername);
		this.idAuthentication = lc.get(0).idAuthentication;
		this.username = lc.get(0).username;
		this.password = lc.get(0).password;
	}

	private void clearAll() {
		this.username = "";
		this.password = "";
		this.idAuthentication=0;
	}
}
